home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3192 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [] overload..(newbie in distress)
  5. Date: 22 Jan 1996 19:34:22 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan22143422@g7240065.bridge.bst.bls.com>
  8. References: <DLGppJ.31C@undergrad.math.uwaterloo.ca>
  9.     <Robert.Lendvai-2101960118330001@129.170.80.94>
  10.     <4dtuam$hf4@news.xmission.com>
  11. NNTP-Posting-Host: bstfirewall.bst.bls.com
  12. In-reply-to: tknarr@xmission.com's message of 21 Jan 1996 17:49:10 GMT
  13.  
  14. In article <4dtuam$hf4@news.xmission.com> tknarr@xmission.com  ( Todd Knarr ) writes:
  15.  
  16. : tthiraku@landen.math.uwaterloo.ca (Thanou Thirakul) wrote:
  17. :>     A[5] = val;  // store val into the fifth node of a linklist. 
  18. :>     val = A[5] ; // returns the value of the fifth node of a linklist.  
  19.  
  20.    T& operator [] (int index);
  21.    T operator [] (int index) const;
  22.  
  23. : It involves the return value of the operator[]() function. If it
  24. : returns a reference, you can use it on the left side of the assignment.
  25. : If it returns a non-reference, you can't.
  26.  
  27. A reference can also be used on the right of an assignment also.
  28.  
  29. Does anyone have any good reasons or references as why you should define the
  30. second of the two operator []'s if you provide the first ?
  31. And if it is necessary what is the argument against
  32.  
  33.    const T& operator [] (int index) const;
  34.  
  35. instead ?
  36.  
  37. Regards
  38.  
  39.     -A.
  40. -- 
  41. | A.Champion                |
  42.